import { Link, Redirect } from 'umi';
import ProLayout from '@ant-design/pro-layout';
import { message, Button } from 'antd';


interface rts {
	path: string, 
	length: number,
	forEach: Function,
	splice: Function,
}

const getRoutes = (routes: rts) : any => {
	if (routes && routes.length) {
		routes.forEach((v: any, idx:number) => {
			if (v.hide || !v.name) routes.splice(idx, 1);
			if (v.routes) {
				getRoutes(v.routes);
			}
		})
	} 
	return routes;
};



export default function Layout (props: any) {
	return (
		<div id="test-pro-layout" style={{height: '100vh'}}>
			<ProLayout
				title={'abc'}
				menuDataRender={() => getRoutes(props.routes) || []}
				menuItemRender={(detail: any) => {
					if (detail.rules) {
						return (
							<div onClick={() => message.warning('暂无权限!')}>{detail.name}</div>
						)
					} else {
						return (
							<Link to={detail.path}>{detail.name}</Link>
						)
					}
					
					
				}}
			>
				{props.children}
			</ProLayout>
		</div>
	)
}